"""
進入爱逛卖家版
"""
import time

import yaml
from uiautomator2 import xpath

from page_object.add_market_page import AddGoodsPage
from page_object.base_page import BasePage
from page_object.guang_page import GuangPage
from page_object.setting_page import SettingPage
from resource.path_info import *

"""
橱窗-仓库管理
"""
class StockPage(GuangPage):


    def get_stock_good_name(self, d, index):
        d.xpath(stockGoodsTitle_xpath %index).wait(timeout=3)
        stockGoodsName = d.xpath(stockGoodsTitle_xpath %index).get_text()[8:]
        print("get stock good name:%s" % stockGoodsName)
        return stockGoodsName


    def switch_on_self_goods(self, d, goodTitle, index):
        if goodTitle == self.get_stock_good_name(d, index):
            d.xpath(switch_on_self_xpath % index).click()
            time.sleep(1)
            if d.xpath(stockGoodsTitle_xpath %index).exists:
                assert goodTitle != self.get_stock_good_name(d, index)
        else:
            for i in range(1,5,1):
                if goodTitle == self.get_stock_good_name(d, i):
                    d.xpath(switch_on_self_xpath % i).click()
                    time.sleep(1)
                    if d.xpath(stockGoodsTitle_xpath % index).exists:
                        assert goodTitle != self.get_stock_good_name(d, i)

        return self

    def switch_on_market_goods(self, d, goodTitle, index):
        if goodTitle == self.get_stock_good_name(d, index):
            d.xpath(switch_on_market_xpath % index).click()
            time.sleep(1)
            if d.xpath(stockGoodsTitle_xpath %index).exists:
                assert goodTitle != self.get_stock_good_name(d, index)
        else:
            for i in range(1,5,1):
                if goodTitle == self.get_stock_good_name(d, i):
                    d.xpath(switch_on_market_xpath % i).click()
                    time.sleep(1)
                    if d.xpath(stockGoodsTitle_xpath % index).exists:
                        assert goodTitle != self.get_stock_good_name(d, i)

        return self


    def check_stock_name(self, d, goodTitle, index):
        print("check_stock_name")
        assert goodTitle == self.get_stock_good_name(d, index)
        return self

    def to_shopWin_page(self, d):
        print("to_shopWin_page")
        d.xpath(shopWin_tab_xpath).click()
        return self